<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>toString()</title>
    <script>
        /* toString() */
        /* 
        
        */
        function Person(name, age, gender) {
            this.name = name;
            this.age = age;
            this.gender = gender;
        }
        //修改Person原型的toString
        Person.prototype.toString = function() {
            //return "我是person";
            return this.name + this.age + this.gender;
        }

        //创建一个per实例
        var per = new Person("孙悟空", 13, "男");

        var per1 = new Person("猪八戒", 33, "男");
        /* 
        当在页面中打印一个对象时，实际上时输出toString()方法的返回值
        如果希望在输出对象时不输出[Object Object],可以为对象添加一个toString()方法

        */

        var result = per.toString();
        var result1 = per1.toString();
        console.log(result1);
        console.log(result);
        console.log(per);
        console.log(per1);
        console.log(per.__proto__.__proto__.hasOwnProperty("toString")); //true
    </script>
</head>

<body>

</body>

</html>